package com.example.demo16_custom_detailssource.config;

import org.springframework.security.web.authentication.WebAuthenticationDetails;

import javax.servlet.http.HttpServletRequest;

public class MyWebAuthenticationDetails extends WebAuthenticationDetails {
    private boolean isPassed;

    /**
     * Records the remote address and will also set the session Id if a session already
     * exists (it won't create one).
     *
     * @param request that the authentication request was received from
     */
    public MyWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        // 将验证码验证的逻辑写在这，通过则将 isPassed 设置为 true
        String code = request.getParameter("code");
        String verifyCode = (String) request.getSession().getAttribute("verifyCode");
        if (code != null && code.equalsIgnoreCase(verifyCode)) {
            this.isPassed = true;
        }
    }

    public boolean isPassed() {
        return isPassed;
    }
}
